package org.devops
//容器化-后端构建
def Build(buildType, buildshell) {
    println("当前选择的构建类型为 ${buildType}")
    def command
    
    switch(buildType.toLowerCase()) {
        case "mvn":
            command = "mvn"  // 直接使用容器内预装的 mvn
            break
        // case "gradle":
        //     command = "gradle"  // 直接使用容器内预装的 gradle
        //     break
        default:
            error "不支持的构建类型: ${buildType}"
    }
    
    sh "${command} ${buildshell}"
}
//非容器--前端构建
def Builds(buildType,buildshell,skipInstall = false){
    def buildTools=["npm": ["cmd": "npm", "installCmd": "npm install"],
        "yarn": ["cmd": "yarn", "installCmd": "yarn install"]] //定义构建工具类型列表

    println("当前选择的构建类型为 ${buildType}")
    if (!buildTools.containsKey(buildType)) {
        error "不支持的构建类型: ${buildType}"
    }
    def toolConfig = buildTools[buildType]
    def buildHome = tool buildType
    // 只有不跳过安装时才执行install
    if (!skipInstall) {
        sh "${buildHome}${toolConfig.installCmd}"
    }
    
    // 执行构建命令
    sh "${buildHome}${toolConfig.cmd} ${buildshell}"
}
//非容器-后端构建
def BuildB(buildType, buildshell) {
    println("当前选择的构建类型为 ${buildType}")
    def command
    
    switch(buildType.toLowerCase()) {
        case "mvn":
            command = "mvn"  // 直接使用容器内预装的 mvn
            break
        case "gradle":
            command = "gradle"  // 直接使用容器内预装的 gradle
            break
        default:
            error "不支持的构建类型: ${buildType}"
    }
    
    sh "${command} ${buildshell}"
}